package com.greysh.members.action;

import com.greysh.members.model.Member;
import com.greysh.members.service.MemberService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 *用户登陆
 *
 */
public class MemberLoginAction  extends ActionSupport{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Member member;
	private MemberService memberService ;
	
	public Member getMember() {
		return member;
	}
	public void setMember(Member member) {
		this.member = member;
	}
	public MemberService getMemberService() {
		return memberService;
	}
	public void setMemberService(MemberService memberService) {
		this.memberService = memberService;
	}
	public String beforeLogin(){
		return "login";
	}
	/**
	 * 
	 * @return 登陆
	 */
	public String login(){
		System.out.println("public String login()");
		System.out.println(member.getMemberName());
		System.out.println(member.getMemberPassword());
		Member tempMember = memberService.findMemberByName(member.getMemberName());
		if(tempMember !=null){
		if(tempMember.getMemberPassword().equals(member.getMemberPassword()))
			return "login_success";
		}
		return "login_error";
	}
	
	/**
	 * 
	 * @return 注销
	 */
	public String logout(){
		return null;
	}
	

//	public void validate()
//	 {
//	 if (null == this.getMember().getMemberName()|| "".equals(this.getMember().getMemberName().trim()))
//	 {
//		 System.out.println("Membername required");
//	 this.addFieldError("member.memberName", "Membername required");
//	 }
//	 if (null == this.getMember().getMemberPassword() || "".equals(this.getMember().getMemberPassword().trim()))
//	 {
//		 System.out.println("password required");
//	 this.addFieldError("member.memberName", "password required");
//	 }
//	 }

	

}
